package com.xqls.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xqls.dal.dao.UserRoleDao;
import com.xqls.dal.model.UserRoleExample;
import com.xqls.dal.model.UserRoleExample.Criteria;
import com.xqls.dal.model.UserRoleKey;
import com.xqls.service.UserRoleKeyService;

@Service
public class UserRoleKeyServiceImpl implements UserRoleKeyService {

	@Autowired private UserRoleDao userRoleDao; 
	
	@Override
	public boolean insertDate(UserRoleKey useRoleKey) {
		return this.userRoleDao.insertDate(useRoleKey);
	}

	@Override
	public boolean updateData(UserRoleKey useRoleKey,String oldRoleId) {
		UserRoleExample example=new UserRoleExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(useRoleKey.getUserId());
		criteria.andRoleIdEqualTo(oldRoleId);
		return this.userRoleDao.updateData(useRoleKey,example);
	}

	@Override
	public boolean deleteData(UserRoleKey userRoleKey) {
		return this.userRoleDao.deleteData(userRoleKey);
	}

	@Override
	public boolean deleteByList(List<String> userIdList,List<String> roleIdList) {
		UserRoleExample example=new UserRoleExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdIn(userIdList);
		criteria.andRoleIdIn(roleIdList);
		
		return this.userRoleDao.deleteDataByExample(example);
	}
	
	@Override
	public UserRoleKey getLastRecord() {
		return this.userRoleDao.getLastRecord();
	}
	
	@Override
	public List<UserRoleKey> getListByUserId(String userId) {
		UserRoleExample example=new UserRoleExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		return this.userRoleDao.getListByExample(example);
	}

	@Override
	public List<UserRoleKey> getListByRoleId(String roleId) {
		UserRoleExample example=new UserRoleExample();
		Criteria criteria = example.createCriteria();
		criteria.andRoleIdEqualTo(roleId);
		return this.userRoleDao.getListByExample(example);
	}

	@Override
	public List<UserRoleKey> getListByKey(String userId, String roleId) {
		UserRoleExample example=new UserRoleExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		criteria.andRoleIdEqualTo(roleId);
		return this.userRoleDao.getListByExample(example);
	}
	
	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.userRoleDao.getListByMap(map);
	}
}
